package com.ruoyi.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.entity.Banner;
import com.ruoyi.common.core.mapper.BannerMapper;
import com.ruoyi.common.core.service.BaseServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;


/**
 * banner图片
 * @date 2024-03-22
 */
@Service
public class BannerServiceImpl extends BaseServiceImpl<BannerMapper, Banner> {

    public void selectPage(Page page, Map<String, Object> param) {
        baseMapper.selectPage(page, param);
    }

    public void doSave(Banner banner) {
        banner.setCreateTime(DateUtils.getNowDate());
        banner.insertOrUpdate();
    }

    public void deleteById(Long id) {
        baseMapper.deleteById(id);
    }

    public void updateUse(Banner banner) {
        Banner old = this.getById(banner.getId());
        old.setInUse(!old.getInUse());
        old.updateById();
    }

    public List<Banner> getBannerList(String bannerPosition) {
        List<Banner> bannerList = baseMapper.getBannerList(bannerPosition);
        return bannerList;
    }
}
